package apiday05.homework.day01;

import java.util.Scanner;

/**
 * 要求用户从控制台输入一个email地址，然后获取该email的用户名(@之前的内容)
 *
 * @author Xiloer
 */
public class Test04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int index;
        String str;
        while (true) {
            System.out.println("请输入email地址：");
            str = sc.nextLine();
            index = str.indexOf("@");
            if (index != -1) {
                break;
            } else {
                System.out.println("格式不正确！请重新输入！");
            }
        }
        String newStr = str.substring(0, index);
        System.out.println(newStr);
        sc.close();
    }
}
